// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    navbar: ['全部'], 
    currentTab:0,
    orderList:[]
  },
  //用户授权登录方法
  login: function()
  {
      let that =this
      wx.getUserProfile({
        desc: '用于登录',
        success(res){
          console.log(res)
          let nickName=res.userInfo.nickName
          let avatarUrl=res.userInfo.avatarUrl   
          wx.login({
            success(res){
              console.log(res)
              if(res.code){
                wx.request({
                  url: 'https://999.tianba.work/api/User/code',
                  data:{
                    code:res.code,
                    nickName:nickName,
                    avatarUrl:avatarUrl,
                  },
                  method: "GET",
                  success(res){
                    console.log(22,res.data)
                    wx.setStorageSync('access_token', res.data.session3rd);
                    that.list()
     
                  }           
                })
              }
              
            }
          })
 
        }
      })
 
      },

      onTabItemTap(){
        let that =this
        wx.request({
          url: 'https://999.tianba.work/api/status/index',
          success(res){
            console.log('状态',res)
          if(res.data.data.status==1){
            if(!wx.getStorageSync('access_token')){
              that.login()           
            }
            else{
              that.list()
            }
          }
          }
        }) 
      },
list:function(){
  let that=this
    wx.request({
      url: 'https://999.tianba.work/api/VOder/list',
      method: "GET",
      data:{
        session3rd:wx.getStorageSync('access_token')
      },
      
      success(res){
        console.log('订单列表',res)
          that.setData({
            orderList:res.data
          })    
      }
    })
  
},
again:function(e){
  let orderId=e.currentTarget.id
  wx.switchTab({
    url: '/pages/index/index',
    success(){
      app.globalData.order_id=orderId
      console.log('传递的下单id',app.globalData.order_id)
      let page=getCurrentPages().pop();
      if(page ==undefined ||page ==null) return;
      page.js();

    }
  })
},



  navbarTap: function(e){ 
    this.setData({ 
    currentTab: e.currentTarget.dataset.idx 
    }) 
    } ,
      // 事件处理函数
  onLoad() {
  

     
    
  },


})
